/*******************************************************************************
 * Copyright (c) 2007 University of Oslo.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University of Oslo - initial API and implementation
 *******************************************************************************/

package com.cea.papyrus.diagram.sequence.sedi.figures;

import org.eclipse.draw2d.AbstractBorder;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Color;

public class CommentBorder extends AbstractBorder {
    // protected int size;
    private final int FLIP_SIZE;
    protected final Insets insets;

    private Color backgroundColor;
    private Color color = ColorConstants.black;

    /**
     * Sets the color.
     * 
     * @param color
     *            the color to set
     */
    public void setColor(Color color) {
        if (color != null) {
            this.color = color;
        }
    }

    /**
     * Sets the backgroundColor.
     * 
     * @param backgroundColor
     *            the backgroundColor to set
     */
    public void setBackgroundColor(Color backgroundColor) {
        if (backgroundColor != null) {
            this.backgroundColor = backgroundColor;
        }
    }

    public CommentBorder(final int flipSize) {
        super();
        FLIP_SIZE = flipSize;
        int top = 4;
        int bottom = 4;
        int left = 6;
        int right = 6 - FLIP_SIZE;
        insets = new Insets(top, left, bottom, right);
    }

    public Insets getInsets(IFigure figure) {
        return insets;
    }

    public void paint(IFigure figure, Graphics g, Insets in) {
        final Rectangle r = figure.getBounds().getCropped(in);
        g.setForegroundColor(this.color);
        g.setBackgroundColor(this.backgroundColor);
        g.drawLine(r.x, r.y, r.right() - FLIP_SIZE, r.y); // top
        g.drawLine(r.right() - FLIP_SIZE, r.y, r.right() - 1, r.y + FLIP_SIZE - 1); // top
        // right
        // diagonal
        g.drawLine(r.right() - 1, r.y + FLIP_SIZE, r.right() - 1, r.bottom() - 1); // right
        g.drawLine(r.x, r.bottom() - 1, r.right() - 1, r.bottom() - 1); // bottom
        g.drawLine(r.x, r.y, r.x, r.bottom() - 1); // left
        g.drawLine(r.right() - FLIP_SIZE, r.y, r.right() - FLIP_SIZE, r.y + FLIP_SIZE); // flip
        // vertical
        g.drawLine(r.right() - FLIP_SIZE, r.y + FLIP_SIZE, r.right() - 1, r.y + FLIP_SIZE); // flip
        // horizontal
    }
}